package com.liang.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liang.entity.User;
import com.liang.mapper.UserMapper;
import com.liang.service.UserService;
import com.liang.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl  implements UserService {


    UserMapper userMapper;

    @Autowired
    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public User getUserById(Integer id) {

        return userMapper.getById(id);


    }

    @Override
    public Result<User> login(User user) {
        User userLogin = userMapper.selectUserByNamePassword(user);
        if (userLogin!=null) {

            userLogin.setPassword("");

            return Result.success(userLogin,"login_OK!");
        }

        return new Result<>(false, 200, "login_false!");
    }

    @Override
    public PageInfo<User> getAllByPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);

       List<User> userList = userMapper.selectAll();

       return new PageInfo<>(userList,5);

    }
}
